<template>
    <view class="page">
		<block v-if="url.length > 0">
			<web-view :src="url"></web-view>
		</block>
    </view>
</template>

<script>
    import { mapState, mapActions } from 'pinia';
    import { useUserInfoStore, useConfigStore } from '@/store/index';
    import { isBoolean } from '@/common/common';
    // import { dispatchClient } from '@/common/api-adviser';
	export default {
        data() {
            return {
                url: '',
                title: '',
                image: '',
                start_time: 0,
                pid: '',
                share: false
            }
        },
        computed:{
            ...mapState(useUserInfoStore, ['userInfo']),
        },
        
        //分享,webViewUrl为webView的url
        onShareAppMessage(res) {
            const that = this;
        	return {
                title: this.title,
                imageUrl: this.image,
        		desc: this.title,
        	    path: `/pages/product/article/detail/index?url=${encodeURIComponent(that.url || '')}&productId=${that.pid}&share=true&puid=${that.userInfo.id}&title=${that.title}&prepage=楼盘文章-${that.pid}-${that.title}`,
        		//#ifdef MP-TOUTIAO
        		templateId: '3e9tvurff9vob6ot7u'
        		//#endif
        	}
        },
        
        onLoad(options){
            const that = this;
            let { productId='', url, title='', image, puid='', share=false } = options;
            if(puid) {
                this.setPuid(puid)
            }
            if(title && title !== 'undefined') {
                this.title = title;
                uni.setNavigationBarTitle({
                    title
                });
            }
            this.pid = productId&&productId!=='undefined'?productId:'';
            this.share = isBoolean(share);
            this.url = decodeURIComponent(url);
            this.start_time = (new Date()).getTime();
            
            if(this.pid){
            	uni.$check_and_login(function () {
                    //绑定客户
                    // dispatchClient({
                    //     share: that.share,
                    //     puid: puid&&puid!=='undefined'?puid:'',
                    //     pid: that.pid
                    // });
            	})
            }
            this.image = decodeURIComponent(image || 'https://image.srea.org.cn/xcx/xcx-share-image.jpg');
        },

        methods:{
            ...mapActions(useConfigStore, ['setPuid'])
        }
    }
</script>
